package com.wjb.xietong.server.login;

import org.json.JSONObject;
import com.wjb.xietong.server.BaseResponseDataParse;
import com.wjb.xietong.server.HeaderInfoResponse;
import com.wjb.xietong.util.IDs;
import com.wjb.xietong.util.LogD;

public class LoginResponse extends BaseResponseDataParse {
	private static LoginResponse instance = null;
	private HeaderInfoResponse headerInfo = null;

	private long id = 0l;
	private String nick = null;
	private long companyId = 0l;
	private String workNick = null;
	private String email = null;
	private long crmSys = 0l;
	private String companyName = null;
	private int loginType = 0;
	private String userName = null;
	private String password = null;

	private String serverVersion = null;
	private String versionDesc = null;
	private LoginResponse() {

	}

	public static synchronized LoginResponse instance() {
		if (null == instance) {
			instance = new LoginResponse();
		}
		return instance;
	}

	@Override
	public void initData() {
		setHeaderInfo(null);
		setCompanyId(0l);
		setCompanyName(null);
		setCrmSys(0l);
		setEmail(null);
		setId(0l);
		setLoginType(0);
		setNick(null);
		setPassword(null);
		setUserName(null);
		setWorkNick(null);
	}

	@Override
	public boolean parseJsonObj(JSONObject response) {
		initData();

		if (null == response) {
			LogD.output("Exception: response is null");
			return false;
		}

		if (!checkRespCode(response)) {
			headerInfo = new HeaderInfoResponse();
			headerInfo.parseJsonObj(response);
			setHeaderInfo(headerInfo);
			return false;
		}

		if (response.has(IDs.ID)) {
			setId(response.optLong(IDs.ID));
		}

		if (response.has(IDs.NICK)) {
			setNick(response.optString(IDs.NICK));
		}

		if (response.has(IDs.COM_ID)) {
			setCompanyId(response.optLong(IDs.COM_ID));
		}

		if (response.has(IDs.WORK_NICK)) {
			setWorkNick(response.optString(IDs.WORK_NICK));
		}

		if (response.has(IDs.EMAIL)) {
			setEmail(response.optString(IDs.EMAIL));
		}

		if (response.has(IDs.CRM_SYS)) {
			setCrmSys(response.optLong(IDs.CRM_SYS));
		}

		if (response.has(IDs.COM_NAME)) {
			setCompanyName(response.optString(IDs.COM_NAME));
		}

		if (response.has(IDs.LOGIN_TYPE)) {
			setLoginType(response.optInt(IDs.LOGIN_TYPE));
		}

		if (response.has(IDs.USER_NAME)) {
			setUserName(response.optString(IDs.USER_NAME));
		}

		if (response.has(IDs.PASSWORD)) {
			setPassword(response.optString(IDs.PASSWORD));
		}
		
		if (response.has(IDs.ANDROID_VERSION)) {
			setVersion(response.optString(IDs.ANDROID_VERSION));
		}
		if (response.has(IDs.ANDROID_UPDATE_DESC)) {
			setVersionDesc(response.optString(IDs.ANDROID_UPDATE_DESC));
		}
		
		return true;
	}

	public HeaderInfoResponse getHeaderInfo() {
		return headerInfo;
	}

	public void setHeaderInfo(HeaderInfoResponse headerInfo) {
		this.headerInfo = headerInfo;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getNick() {
		return nick;
	}

	public void setNick(String nick) {
		this.nick = nick;
	}

	public long getCompanyId() {
		return companyId;
	}

	public void setCompanyId(long companyId) {
		this.companyId = companyId;
	}

	public String getWorkNick() {
		return workNick;
	}

	public void setWorkNick(String workNick) {
		this.workNick = workNick;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public long getCrmSys() {
		return crmSys;
	}

	public void setCrmSys(long crmSys) {
		this.crmSys = crmSys;
	}

	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public int getLoginType() {
		return loginType;
	}

	public void setLoginType(int loginType) {
		this.loginType = loginType;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	public void setVersion(String version){
		serverVersion = version;
	}
	public String getNewVersion(){
		return serverVersion;
	}
	public void setVersionDesc(String desc){
		versionDesc = desc;
	}
	public String getVersionDesc(){
		return versionDesc;
	}
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}
